package com.east.controller.project;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.east.bean.Project;
import com.east.service.project.ProjectService;
import com.east.utils.PageJson;
import com.east.utils.Pagenation;
import com.east.utils.Result;
import com.east.utils.ResultUtil;
import com.github.pagehelper.Page;
@RestController
@RequestMapping("project")
public class ProjectController {
		@Autowired
		ProjectService projectService;
		
		@GetMapping("all")
		@RequiresPermissions("project:all")
		public Result findByPage(Pagenation pagenation,String key,String startTime ,String endTime) {
			Page<Project> findByPage = projectService.findByPage(pagenation, key, startTime, endTime);
			Object pageJson = new PageJson<Project>().pageJson(findByPage);
			return ResultUtil.success(pageJson);
		}
		@GetMapping("findOne")
		@RequiresPermissions("project:findOne")
		public Result findByfindOne(Project project) {
			 Project findByProjectId = projectService.findByProjectId(project);
			return ResultUtil.success(findByProjectId);
		}
		@PostMapping("add")
		@RequiresPermissions("project:add")
		public Result findByAdd(Project project) {
			  boolean saveProject = projectService.saveProject(project);
			  if(saveProject) {
				  return ResultUtil.success("保存成功");
			  }else {
				  return ResultUtil.success("保存失败");
			  }
			
		}
		@PostMapping("update")
		@RequiresPermissions("project:update")
		public Result findByUpdate(Project project) {
			  boolean updateProject = projectService.updateProject(project);
			  if(updateProject) {
				  return ResultUtil.success("修改成功");
			  }else {
				  return ResultUtil.success("修改失败");
			  }
		}
		
		@DeleteMapping("del")
		@RequiresPermissions("project:del")
		public Result findByDel(Project project) {
			 boolean findByProjectId = projectService.delProject(project);
			 if(findByProjectId) {
				  return ResultUtil.success("删除成功");
			 }else {
					  return ResultUtil.success("删除失败");
			 }
		}
}
